import useDesignerStore from "@/store/Designer";
import { useMemo } from "react";
import { useCurrentNode } from "./useCurrentNode";
import { useEdges, useNodes } from "@xyflow/react";

export const useGraph = () => {
    const edges = useEdges()
    const nodes = useNodes()
    return {edges, nodes}
}

export const useDAG = () => {
    const edges = useEdges()
    const nodes = useNodes()
    return useMemo(() => {
        const ns = nodes.map(n=>{
            return {
                id: n.id,
                label: n.data?.label,
                renderKey: "SOURCE_SQL",
                param: JSON.stringify({
                    ...n.data,
                    system: 'gauss',
                    columns: n.data?.columns?.map(a=>a.columnName)
                })
            }
        })
        return {edges, nodes: ns}
    }, [nodes, edges])
}